package leetcode.simple._previous;


import java.util.LinkedList;
import java.util.Queue;

//求二叉树的镜像，左子树变成右子树，右子树变成左子树
public class MirrorBinaryTree {

    public TreeNode mirrorTree(TreeNode root) {
        Queue<TreeNode> queue = new LinkedList<>();
        queue.add(root);

        while (!queue.isEmpty()) {
            TreeNode node = queue.poll();

            TreeNode temp = node.left;

            node.left = node.right;
            node.right = temp;

            if (node.left != null) queue.add(node.left);

            if (node.right != null) queue.add(node.right);
        }

        return root;

    }
}


class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    TreeNode(int x) {
        val = x;
    }
}